package xxx.pojo.typehandler;

import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import xxx.common.utils.JsonUtil;

import java.util.List;

/**
 * List<Long>与String互转
 *
 * @author yuanchengman
 * @date 2021-08-17
 */
@MappedTypes({List.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
public class ListLongTypeHandler extends AbstractJsonTypeHandler<List<Long>> {
    @Override
    protected List<Long> parse(String json) {
        return JsonUtil.string2Obj(json, new TypeReference<>() {
        });
    }

    @Override
    protected String toJson(List<Long> obj) {
        return JsonUtil.obj2String(obj);
    }
}
